<template>
	<view>
		<st-mc-framework :navTitle="ModuleTitle" @changeLevel="changeLevel"
			@AddModuleData_select='AddModuleData_select'>
			<template #workbench>
				<view class="TabsBox">


				</view>


			</template>

			<!-- 主内容 -->
			<template #content>
				<view class="content">
					<z-paging ref="paging" v-model="contents" @query="queryList" :fixed="false" class="z_paging">
						<view class="table" style="overflow-x: auto;width: 100%;">
							<table>
								<tr>
									<th>人员名称</th>
									<th>上班打卡时间</th>

									<th>班次</th>

								</tr>
								<tbody>
									<tr v-for="(item,index) in contents" @click="planIDClick(item)">
										<td>
											{{item.EmplName}}
										</td>
										<td>{{item.ClockIn}}</td>

										<td>{{item.ShiftName}}</td>
									</tr>
								</tbody>
							</table>

						</view>

					</z-paging>

				</view>




			</template>

			<view class="search">
				<u-icon name="search" color="#fff" size="30" @click="search"></u-icon>
			</view>


			<uni-popup ref="popup" type="bottom" background-color="#fff" border-radius="10px 10px 0 0"
				@change="changePopup">
				<view class="popup_content">
					<u-cell-group :border='false'>
						<!-- 
							<u-cell title="班次" :isLink="false" :value="FormData.ShiftName"
								@click="addBShiftName()"></u-cell> -->
						<u-cell title="开始时间" :isLink="false" :value='FormData.FBDate' @click="addTime('开始')"></u-cell>
						<u-cell title="结束时间" :isLink="false" :value='FormData.FEDate' @click="addTime('结束')"></u-cell>
					</u-cell-group>
					<view class="bottomBtns">
						<button block @click="submit">
							查 &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp 询
						</button>
					</view>

				</view>
			</uni-popup>


		</st-mc-framework>
		<u-datetime-picker :show="show" v-model="value1" mode="date" @cancel='show = false'
			@confirm='pickerConfirm'></u-datetime-picker>
		<m-loading :text="loadingName" v-model="showMLoading" :showClose="false"
			maskBackgroundColor="rgba(0,0,0,0.3)"></m-loading>

	</view>
</template>

<script>
	import {
		getTimeStamp,
		getFormatDateTime,
		getBefore7DateTime,
		formatDateTime,
		navigateMixin,
		baseAddModuleData_select,
		getchangeLevel
	} from '@/st_mes_zs/common/base.js';

	export default {
		mixins: [navigateMixin, baseAddModuleData_select],
		data() {
			return {
				ModuleTitle: '',
				showMLoading: false,
				loadingName: '正在加载中……',
				contents: [],
				FormData: {
					PageIndex: 1,
					PageSize: 30,
					FBDate: '',
					FEDate: '',
					EmplID: ''
				},
				show: false,
				value1: Number(new Date()),
				TimeName: '',
				disabled: false,

			};
		},
		onLoad() {
			var that = this
			this.showMLoading = true
			this.ModuleTitle = this.$store.state.appConfigInfo.ActiveModule.ModuleName
			this.FormData.FBDate = getBefore7DateTime()
			this.FormData.FEDate = getFormatDateTime(new Date())
			this.FormData.EmplID = this.$store.state.UserInfo.EmplID
			this.$store.state.GuyueModule.MesBasicInfo.Status.ClockStatusTitle = '其他'
		},
		onShow() {},
		onBackPress(options) { // 监听页面返回
			if (options.from == 'navigateBack') { // 通过点击路由返回
				return false;
			} else if (options.from == 'backbutton') { // 通过外置返回
				return true;
			}
		},
		mounted() {

		},

		methods: {
			planIDClick(item) {
				let that = this;
				var url
				var msgShow = false
				let routes = getCurrentPages();
				let obj = {
					Name: '',
					APPFunID: '',
					length: routes.length + 1,
					routes: routes.length,
				}
				obj.Name = '报工'
				obj.APPFunID = '报工'
				url = `/st_mes_zs/production/reportingDetail?item=${JSON.stringify(item)}`
				that.GonavigateTo(obj, url)
			},

			GonavigateTo(obj, url) {
				let that = this;
				this.$safeNavigate({
					targetUrl: url, // 目标页面路径
					payload: obj, // 要传递的数据
				});
				// 	if (that.disabled == false) {
				// 		// 立即禁用点击
				// 		that.disabled = true
				// 		// 执行跳转逻辑
				// 		let newData = JSON.parse(JSON.stringify(this.$store.state.GuyueModule.ModuleData_select));
				// 		newData.push(obj);
				// 		this.$store.commit('GuyueModule/ChangeAndSetStateData', {
				// 			Name1: 'ModuleData_select',
				// 			data: newData
				// 		})

				// 		const newEquipment = JSON.parse(JSON.stringify(this.$store.state.GuyueModule.MesBasicInfo));
				// 		newEquipment.ModuleData_select = newData
				// 		console.log(newEquipment);
				// 		that.$store.commit('GuyueModule/ChangeAndSetStateData', {
				// 			Name1: 'MesBasicInfo',
				// 			data: newEquipment
				// 		})
				// 		var MesBasicInfoList = that.$store.state.GuyueModule.MesBasicInfoList;
				// 		var index = MesBasicInfoList.findIndex((item) => item.warehouse.EquipmentID ==
				// 			newEquipment.warehouse.EquipmentID)
				// 		console.log(index);
				// 		MesBasicInfoList[index] = newEquipment
				// 		that.$store.commit('GuyueModule/ChangeAndSetStateData', {
				// 			Name1: 'MesBasicInfoList',
				// 			data: MesBasicInfoList
				// 		})

				// 		uni.navigateTo({
				// 			url: url,
				// 			animationType: 'slide-in-right', // 动画类型
				// 			animationDuration: 100 // 动画时长
				// 		});
				// 		// 2秒后恢复点击
				// 		setTimeout(() => {
				// 			that.disabled = false
				// 		}, 2000)
				// 	}
			},
			async AddModuleData_select(res) {
				try {
					console.log(res);
					console.log(res);
					console.log(res);
					console.log(res);
					console.log(res);
					const backDelta = await this.GetModuleData_select(res);
				} catch (error) {
					console.error('返回操作失败:');
				}
			},
			// AddModuleData_select() {
			// 	var that = this
			// 	let routes = getCurrentPages(); //当前页面栈
			// 	if (this.$refs.framework && typeof this.$refs.framework.ChangeTabsClick == 'function') {
			// 		that.$refs.framework.ChangeTabsClick()
			// 	}
			// 	let newData = JSON.parse(JSON.stringify(this.$store.state.GuyueModule.MesBasicInfo.ModuleData_select));
			// 	const lastItem = newData[newData.length - 1];
			// 	if (lastItem && lastItem.nood && lastItem.nood.length > 0) {
			// 		that.GolastItemUrl(lastItem.url, lastItem.nood[0].pages)
			// 	} else if (lastItem && lastItem.path) {
			// 		that.GolastItemUrl(lastItem.url)
			// 	} else {
			// 		let backIndex = routes.length - lastItem.length; // 计算返回页面栈数
			// 		uni.$emit('refreshList');
			// 		uni.navigateBack({
			// 			delta: backIndex
			// 		});
			// 	}
			// },
			// GolastItemUrl(url, moduleData) {
			// 	var that = this
			// 	if (url) {
			// 		uni.navigateTo({
			// 			url: url
			// 		});
			// 	} else {
			// 		that.moduleData_show = moduleData
			// 	}
			// },
			addTime(name) {
				this.TimeName = name
				if (this.TimeName == '开始') {
					this.value1 = Number(getTimeStamp(this.FormData.FBDate))
				} else {
					this.value1 = Number(getTimeStamp(this.FormData.FEDate))
				}
				this.show = true
			},

			pickerConfirm(e) {
				var time = getFormatDateTime(e.value)
				if (this.TimeName == '开始') {
					this.FormData.FBDate = time
				} else {
					this.FormData.FEDate = time
				}
				this.show = false
			},
			search() {
				this.$refs.popup.open('bottom')
			},


			changePopup() {

			},
			submit() {
				this.$refs.popup.close('bottom')
				this.contents = []; // 假设这是异步获取数据的操作
				this.$refs.paging.reload();
			},
			queryList(pageNo) {
				let that = this;
				try {
					that.FormData.PageIndex = pageNo
					that.Request.request('getClockRecords', this.FormData, (ret) => {
						if (ret.status == 200) {
							that.showMLoading = false
							ret.data.ds.map((item) => {
								item.ClockIn = formatDateTime(item.ClockIn)
								item.ClockOut = formatDateTime(item.ClockOut)
							})
							that.$refs.paging.complete(ret.data.ds);
						} else {
							that.showMLoading = false
						}
					})
				} catch (e) {
					console.log(e)
					that.showMLoading = false
					this.$utils.hideLoading();
					this.$utils.msg('请求失败请重试')
				}

			},

			changeLevel(list, data, row) {
				getchangeLevel(data)
				uni.$emit('refreshList');
			},
			clearHovered() {
				this.hoveredIndex = null; // 清除hover的tr索引  
			},

		}
	}
</script>

<style lang="scss" >
	@import "../css/index.css";
</style>